package com.ybu.controller;

import com.ybu.common.Constants;
import com.ybu.common.JwtUtils;
import com.ybu.common.R;
import com.ybu.pojo.vo.UserLoginVO;
import com.ybu.service.AddFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("api/favorite")
public class AddFavoriteController {
    @Autowired
    private AddFavoriteService addFavoriteService;

    @PostMapping("add/{productId}")
    public R<Void> addFavorite(@PathVariable Integer productId, HttpServletRequest request ){
       String token = request.getHeader(Constants.TOKEN_HEADER);
       UserLoginVO userLoginVO = JwtUtils.parseToken(token);
        addFavoriteService.addFavorite(productId,userLoginVO);
        return R.ok();
    }
}
